package t4;

import java.util.List;

import t4bean.PurchaseDateBean;
import t4bean.SalesvolumDateBean;
import t4bean.StallBean;

import java.util.ArrayList;

/**
 * 显示某段时间利润
 *
 */
public class ShowDateProfit {
	/**
	 * 加入折扣 用这段时间所有出售水果的钱减去所有进货的钱
	 */
	public void showDateProfit(StallBean stall, Integer day1, Integer day2) {
		List<PurchaseDateBean> purDateList = new ArrayList<PurchaseDateBean>();
		List<SalesvolumDateBean> salesDateList = new ArrayList<SalesvolumDateBean>();

		for (PurchaseDateBean purDate : stall.getPurDateList()) {
			if (purDate.getDay() >= day1 && purDate.getDay() <= day2) {
				purDateList.add(purDate);
			}
		}
		for (SalesvolumDateBean salDate : stall.getSalDateList()) {
			if (salDate.getDay() >= day1 && salDate.getDay() <= day2) {
				salesDateList.add(salDate);
			}
		}
		Integer money = 0;
		int n = 0;
		for (PurchaseDateBean purDate : purDateList) {
			for (SalesvolumDateBean salDate : stall.getSalDateList()) {
				if (purDate.getFruit().getName().equals(salDate.getFruit().getName())) {
					money = money + ((salDate.getSr().getSalesVolume() * salDate.getSr().getDiscount() / 10
							* salDate.getFruit().getPrice())
							- purDate.getPo().getPurchaseQuantity() * purDate.getFruit().getCost());
					n = 1;
				}
			}
			if (n == 0) {
				money = money - purDate.getPo().getPurchaseQuantity() * purDate.getFruit().getCost();
			} else {
				n = 0;
			}
		}
		System.out.println("利润：" + money);
		System.out.println();
	}
}
